<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>vue</title>
    <script src="https://cdn.bootcss.com/vue/2.5.14/vue.js"></script>

</head>

<body>
    <div id="app">
        <h1>{{x0}}</h1>
        <h1>{{y0}}</h1>
        <div id="test_3"  >
            <img src="./src/www.bootcss.com_p_responsive-nav.js_.png"  @mousedown="start" @mouseup="stop" @mousemove="move"   :style="style">
        </div>
    </div>


</body>
<script>
    var app = new Vue({
        el:"#app",
        data: function () {
            return {
                canDrag: false,
                x0: 0,
                y0: 0,
                x1: 0,
                y1: 0,
                style: null
            }
        },
        methods: {
            start: function (e) {
                console.log("start:"+this.x0)
                //鼠标左键点击
                if (e.button == 0) {
                    this.canDrag = true;
                    //记录鼠标指针位置
                    this.x0 = e.clientX;
                    this.y0 = e.clientY;
                }
            },
            stop: function (e) {
                console.log("stop:"+this.x0)
                this.canDrag = false;
            },
            
            move: function (e) {
                console.log("move:"+this.x0)
                if (this.canDrag == true) {
                    this.x1 = e.clientX;
                    this.y1 = e.clientX;
                    let x = this.x1 - this.x0;
                    let y = this.y1 - this.y0;
                    let img = document.querySelector("#test_3 img");
                    this.style = `left:${img.offsetLeft + x}px;top:${img.offsetTop + y}px`;
                    this.x0 = this.x1;
                    this.y0 = this.y1;
                }
            }
        }
    })

</script>

</html>